<?php

namespace app\index\controller;

use app\index\model\Htrole_operation;
use app\index\model\HtroleOperation;
use app\index\model\Htuser_htrole;
use app\index\model\Login_model;
use Firebase\JWT\JWT;
use think\Controller;
use think\facade\Session;
use think\Request;

class Login
{
    public function index()
    {
        $user = new Login_model();
        config('default_return_type','json');
        try{
            $me = $user->login();
            $role_id = Htuser_htrole::get(['htrole_id'=>$me['id']]);
            $url = HtroleOperation::getUrl($role_id['htrole_id']);
//            $urls = [];
//            foreach ($url as $row){
////                $urls[$row['url']] = true;
//                $urls[] = $row['url'];
//            }
            $token = JWT::encode($url, config('jwt_key'));
            Session::set("token",$token);
            return['status'=>true,
                'token'=>$token,
                'url'=>$url];
        }catch (\Exception $f){
            return['status'=>false,'error'=>$f->getMessage()];
        }
    }
//    public function read($id)
//    {
//        //
//    }
}
